/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package com.maschinenstuermer.profiler.trace.impl;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;
import org.eclipse.emf.ecore.impl.ENotificationImpl;

import com.maschinenstuermer.profiler.trace.MethodInvocation;
import com.maschinenstuermer.profiler.trace.Metrics;
import com.maschinenstuermer.profiler.trace.TracePackage;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Method Invocation</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link com.maschinenstuermer.profiler.trace.impl.MethodInvocationImpl#getSelfMetrics <em>Self Metrics</em>}</li>
 *   <li>{@link com.maschinenstuermer.profiler.trace.impl.MethodInvocationImpl#getMethod <em>Method</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class MethodInvocationImpl extends CompositeInvocationImpl implements MethodInvocation {
	/**
	 * The cached value of the '{@link #getSelfMetrics() <em>Self Metrics</em>}' containment reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getSelfMetrics()
	 * @generated
	 * @ordered
	 */
	protected Metrics selfMetrics;

	/**
	 * The default value of the '{@link #getMethod() <em>Method</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getMethod()
	 * @generated
	 * @ordered
	 */
	protected static final String METHOD_EDEFAULT = null;

	/**
	 * The cached value of the '{@link #getMethod() <em>Method</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getMethod()
	 * @generated
	 * @ordered
	 */
	protected String method = METHOD_EDEFAULT;

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected MethodInvocationImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return TracePackage.Literals.METHOD_INVOCATION;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public Metrics getSelfMetrics() {
		return selfMetrics;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public NotificationChain basicSetSelfMetrics(Metrics newSelfMetrics, NotificationChain msgs) {
		Metrics oldSelfMetrics = selfMetrics;
		selfMetrics = newSelfMetrics;
		if (eNotificationRequired()) {
			ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, TracePackage.METHOD_INVOCATION__SELF_METRICS, oldSelfMetrics, newSelfMetrics);
			if (msgs == null) msgs = notification; else msgs.add(notification);
		}
		return msgs;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setSelfMetrics(Metrics newSelfMetrics) {
		if (newSelfMetrics != selfMetrics) {
			NotificationChain msgs = null;
			if (selfMetrics != null)
				msgs = ((InternalEObject)selfMetrics).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - TracePackage.METHOD_INVOCATION__SELF_METRICS, null, msgs);
			if (newSelfMetrics != null)
				msgs = ((InternalEObject)newSelfMetrics).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - TracePackage.METHOD_INVOCATION__SELF_METRICS, null, msgs);
			msgs = basicSetSelfMetrics(newSelfMetrics, msgs);
			if (msgs != null) msgs.dispatch();
		}
		else if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, TracePackage.METHOD_INVOCATION__SELF_METRICS, newSelfMetrics, newSelfMetrics));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public String getMethod() {
		return method;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setMethod(String newMethod) {
		String oldMethod = method;
		method = newMethod;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, TracePackage.METHOD_INVOCATION__METHOD, oldMethod, method));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case TracePackage.METHOD_INVOCATION__SELF_METRICS:
				return basicSetSelfMetrics(null, msgs);
		}
		return super.eInverseRemove(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
			case TracePackage.METHOD_INVOCATION__SELF_METRICS:
				return getSelfMetrics();
			case TracePackage.METHOD_INVOCATION__METHOD:
				return getMethod();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
			case TracePackage.METHOD_INVOCATION__SELF_METRICS:
				setSelfMetrics((Metrics)newValue);
				return;
			case TracePackage.METHOD_INVOCATION__METHOD:
				setMethod((String)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case TracePackage.METHOD_INVOCATION__SELF_METRICS:
				setSelfMetrics((Metrics)null);
				return;
			case TracePackage.METHOD_INVOCATION__METHOD:
				setMethod(METHOD_EDEFAULT);
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case TracePackage.METHOD_INVOCATION__SELF_METRICS:
				return selfMetrics != null;
			case TracePackage.METHOD_INVOCATION__METHOD:
				return METHOD_EDEFAULT == null ? method != null : !METHOD_EDEFAULT.equals(method);
		}
		return super.eIsSet(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public String toString() {
		if (eIsProxy()) return super.toString();

		StringBuffer result = new StringBuffer(super.toString());
		result.append(" (method: ");
		result.append(method);
		result.append(')');
		return result.toString();
	}

} //MethodInvocationImpl
